package com.example.app.components.MyProgressIndicator

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ProgressIndicatorDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.example.app.components.MySpacer.MySpacer
import com.example.app.mainViewModel
import com.example.app.viewmodel.MainViewModel

@Composable
fun MyGlobalCircularProgressIndicator(

        modifier: Modifier = Modifier.size(24.dp),
        color: Color = MaterialTheme.colorScheme.background,
        strokeWidth: Dp = ProgressIndicatorDefaults.CircularStrokeWidth,
        trackColor: Color = ProgressIndicatorDefaults.circularIndeterminateTrackColor,
        strokeCap: StrokeCap = ProgressIndicatorDefaults.CircularIndeterminateStrokeCap,
) {
    var showMyCircularProgressIndicator =
        mainViewModel.showMyCircularProgressIndicator.collectAsState()
    if (showMyCircularProgressIndicator.value) {
        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.Center
        ) {
            MySpacer(modifier = Modifier.height(100.dp))
            Column(
                modifier = Modifier
                    .clip(CircleShape)
                    .background(Color.Black.copy(alpha = .5f))
                    .padding(6.dp),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center
            ) {
                CircularProgressIndicator(
                    modifier,
                    color,
                    strokeWidth,
                    trackColor,
                    strokeCap,
                )
            }
        }
    }
}